package com.itita.ww2.data;

import com.smartfoxserver.v2.entities.data.ISFSArray;
import com.smartfoxserver.v2.entities.data.ISFSObject;

public class ArmyConfig {
	public static boolean isLoaded;
	// 
	private static ISFSObject config; // 兵种配置(等级无关)
	private static ISFSObject attribute; // 属性配置(等级相关)
	// 

	public static final void init(ISFSObject data) {
		ArmyConfig.config = data.getSFSObject("config");
		ArmyConfig.attribute = data.getSFSObject("attribute");
		isLoaded = true;
	}

	/**
	 * 获取士兵升级对应经验值
	 */
	public static final int getArmyUpExp(String key, int level) {
		key = key + "_" + level;
		return attribute.getSFSObject(key).getFloat("P012").intValue();
	}

	/**
	 * 获取士兵生产价格
	 */
	public static final int getArmyProducePrice(String key, int level) {
		key = key + "_" + level;
		return attribute.getSFSObject(key).getFloat("P011").intValue();
	}

	/**
	 * 获取兵种对应最大等级
	 */
	public static final int getArmyMaxLv(String key) {
		return config.getSFSObject("MaxLv").getInt(key);
	}

	/**
	 * 获取兵种生产时间
	 */
	public static final int getArmyProduceTime(String key) {
		return config.getSFSObject("ProduceTime").getInt(key);
	}

	/**
	 * 验证物品对应装备栏的合法性
	 */
	public static final boolean checkArmyEquipItem(String armyCode, String equipGrid, String itemId) {
		ISFSArray grid = config.getSFSObject("EquipGrid").getSFSObject(armyCode).getSFSArray(equipGrid);
		return grid.contains(itemId);
	}

	/**
	 * 获取兵种占用容量
	 */
	public static final int getProportion(String key) {
		return config.getSFSObject("Proportion").getInt(key);
	}
}
